package com.itheima.TCP.线程池;

import java.io.*;
import java.net.Socket;

public class ClientDemo {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("127.0.0.1", 10000);
        //是本地的流，用来读取本地文件的
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("day629_网络编程入门\\abc.jpg"));
        //写到服务器 ---网络中的流
        OutputStream os = socket.getOutputStream();
        //字符缓冲输出流写到本地
        BufferedOutputStream bos = new BufferedOutputStream(os);
        byte[] bys = new byte[1024];
        int len;
        while ((len=bis.read(bys))!=-1){
            bos.write(bys,0,len);//通过网络写到服务器
            bos.flush();
        }
        //给服务器一个结束标记，告诉服务器文件已经传输完毕
        socket.shutdownOutput();
            //字符缓冲输入流
        BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        String line;
        while ((line=br.readLine())!=null){
            System.out.println(line);
        }
    }
}
